Skip to content

Avoid repeated get_span in quote_spanned - #329

Merged
dtolnay merged 1 commit into
dtolnay:masterfrom
Noratrieb:avoid-repeat-expand
Jun 22, 2026
Merged

Avoid repeated get_span in quote_spanned#329
dtolnay merged 1 commit into
dtolnay:masterfrom
Noratrieb:avoid-repeat-expand

Conversation

@Noratrieb

Copy link
Copy Markdown
Contributor

Every group used in quote_spanned would cause a nested quote_spanned to be called for the contents of the group. This caused $crate::__private::get_span($span).__into_span() to be called every time, causing lots of unnecessary code.
By only doing this in the user-facing macro and just reusing the identifier for internal recursion we avoid this extra code.

This cuts the expanded lines of code from tracing-attributes by almost 300.

Every group used in `quote_spanned` would cause a nested `quote_spanned`
to be called for the contents of the group. This caused
`$crate::__private::get_span($span).__into_span()` to be called every
time, causing lots of unnecessary code.
By only doing this in the user-facing macro and just reusing the
identifier for internal recursion we avoid this extra code.

This cuts the expanded lines of code from `tracing-attributes` by almost
300.

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread src/lib.rs
// Special case rules for two tts, for performance.
($span:ident=> # $var:ident) => {
let mut _s = $crate::__private::TokenStream::new();
let _: $crate::__private::Span = $crate::__private::get_span($span).__into_span();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _: $crate::__private::Span = $crate::__private::get_span($span).__into_span();

@dtolnay
dtolnay merged commit 0b33821 into dtolnay:master Jun 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants